package com.zara.store.client.view.swing.table;


public class BasketTableModel extends StoreTableModel {
	
	private static final int AMOUNT = 1;
	private static final int OFFER = 2;
	private static final long serialVersionUID = 1L;
	private TableOnChangeAction amountAction;
	private TableOnChangeAction offerAction;
	
	public BasketTableModel() {
		super();
		this.setColumnIdentifiers(new Object[]{"Producto", "Cantidad", "Oferta", "Precio x1", "Total" });
	}
	
	public Class<?> getColumnClass(int columnIndex) {
		if(columnIndex==2)
			return Boolean.class;
		return String.class;
	}

	public boolean isCellEditable(int rowIndex, int columnIndex) {
		return columnIndex==1 || columnIndex==2;
	}

	public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
		super.setValueAt(aValue, rowIndex, columnIndex);
		if(columnIndex==OFFER) { //cambia oferta vs. precio lista
			offerAction.onChange(rowIndex, null);
		} else if(columnIndex==AMOUNT) {//cambia la cantidad de un producto
			amountAction.onChange(rowIndex, aValue.toString());
		}
	}

	public void setOfferAt(Object aValue, int rowIndex) {
		super.setValueAt(aValue, rowIndex, OFFER);
	}

	public void setOnChangeAmountAction(TableOnChangeAction action) {
		this.amountAction = action;
	}
	
	public void setOnChangeOfferAction(TableOnChangeAction action) {
		this.offerAction = action;
	}
	
};
